package com.yy.wga.goods.service.controller;

import com.yy.wga.common.core.dto.Result;
import com.yy.wga.resource.feign.request.SharerProductSetCommissionReq;
import com.yy.wga.resource.feign.request.SharerSetCommissionReq;
import com.yy.wga.resource.feign.response.PromoterStatusResp;
import com.yy.wga.resource.service.manage.PromoterManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 推客管理
 */
@RestController
@RequestMapping("api/promoter")
@Slf4j
public class PromoterController implements PromoterFeign {

    @Resource
    private PromoterManager promoterManager;

    /**
     * 获取推客状态
     *
     * @param openId
     */
    @GetMapping("/getPromoterStatus")
    public Result<PromoterStatusResp> getPromoterStatus(@RequestParam("openId") String openId) {
        return Result.success(promoterManager.getPromoterStatus(openId));
    }


    /**
     * 设置推客佣金
     *
     * @param req req
     * @return void
     */
    @PostMapping("/setSharerCommission")
    public Result<Void> setSharerCommission(@RequestBody @Valid SharerSetCommissionReq req) {
        promoterManager.setSharerCommission(req);
        return Result.success();
    }

    /**
     * 设置推客单个商品佣金
     *
     * @param req req
     * @return void
     */
    @PostMapping("/setSharerProductCommission")
    public Result<Void> setSharerProductCommission(@RequestBody @Valid SharerProductSetCommissionReq req) {
        promoterManager.setSharerProductCommission(req);
        return Result.success();
    }

    /**
     * 获取推客单个商品佣金
     *
     * @param spuId spuId
     * @return void
     */
    @PostMapping("/getSharerProductCommission")
    public Result<Integer> getSharerProductCommission(@RequestParam("spuId") String spuId) {
        return Result.success(promoterManager.getSharerProductCommission(spuId));
    }


}
